package com.devframe.srtp.client.handle;

import java.net.URI;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpVersion;
import org.jboss.netty.handler.codec.http.multipart.HttpDataFactory;
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestEncoder;

public abstract class ClientWrapFileHandler {
	protected  static final Log log=LogFactory.getLog(ClientWrapFileHandler.class);
	private String host;
	
	private URI uri;
	
	private String userName;
	
	private String pwd;
	
	private HttpRequest request;
	
	public ClientWrapFileHandler(String host,URI uri,String userName,String pwd){
		this.host=host;
		this.uri=uri;
		this.userName=userName;
		this.pwd=pwd;
		request=new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.POST, uri.toASCIIString());
		this.setHeaderDatas();
	}
	
	
	private  void  setHeaderDatas(){
	        request.setHeader(HttpHeaders.Names.HOST, host);
	        request.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
	        request.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP + ',' +HttpHeaders.Values.DEFLATE);
	        request.setHeader(HttpHeaders.Names.ACCEPT_CHARSET, "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
	        request.setHeader(HttpHeaders.Names.ACCEPT_LANGUAGE, "fr");
	        request.setHeader(HttpHeaders.Names.REFERER, uri.toString());
	        request.setHeader(HttpHeaders.Names.USER_AGENT, "Netty Simple Http Client side");
	        request.setHeader(HttpHeaders.Names.ACCEPT,"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
	   }
	  
	  
	
	
	public abstract HttpPostRequestEncoder wrapRequestData(HttpDataFactory factory);




	public HttpRequest getRequest() {
		return request;
	}


	public String getUserName() {
		return userName;
	}


	public void setUserName(String userName) {
		this.userName = userName;
	}


	public String getPwd() {
		return pwd;
	}


	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
}
